const sql = require('mssql');

/**
 * 
 * 修改密码
 */
const changePassword = async (ctx, next) => {
    const body = ctx.request.body;
    let selectPassSql = `SELECT MM FROM BM_YG WHERE BM ='${body.userId}'`;
    let passResult = await sql.query(selectPassSql);
    if (passResult.recordset[0].MM === body.oldPasswd) {
        let changePassSql = `UPDATE BM_YG SET MM = '${body.newPasswd}' WHERE BM = '${body.userId}'`;
        let changeResult = await sql.query(changePassSql);
        if (changeResult.rowsAffected[0] > 0) {
            // 修改成功
            ctx.body = { result: 1 }
        } else {
            // 修改失败
            ctx.body = { result: 0 }
        }
    } else {
        // 原始密码不正确
        ctx.body = { result: 2 }
    }
  
}


module.exports = {
    'POST /changePassword': changePassword
}